# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/media-video/realplayer/realplayer-10.0.9.ebuild,v 1.4 2007/11/27 11:52:59 zzam Exp $

inherit nsplugins eutils rpm

DESCRIPTION="Google Desktop: Personalize and organize your own computer."
HOMEPAGE="http://desktop.google.com/linux/"
SRC_URI="google-desktop-linux-current.rpm"
LICENSE="Google"
SLOT="0"
IUSE=""
RDEPEND=">=app-shells/bash-3.2
        >=sys-apps/util-linux-2.12"
RESTRICT="strip test fetch"
KEYWORDS="x86"

S="${WORKDIR}"

pkg_nofetch() {
	einfo "Download Google Desktop manually from Google's website at"
	einfo ${HOMEPAGE}
	einfo ""
	einfo "Choose 'Download Google Desktop'"
	einfo "http://desktop.google.com/linux/"
	einfo ""
	einfo "Then place the file ${SRC_URI}"
	einfo "into ${DISTDIR} and restart the emerge."
}

pkg_setup() {
        # This is a binary x86 package => ABI=x86
        # Please keep this in future versions
        # Danny van Dyk <kugelfang@gentoo.org> 2005/03/26
        has_multilib_profile && ABI="x86"
}

src_unpack() {
	rpm_src_unpack

	sed -i -e "s:^InstallDesktopMenu$:#InstallDesktopMenu:" "${S}"/opt/google/desktop/bin/post_install.sh
	sed -i -e "s:^UninstallDesktopMenu$:#UninstallDesktopMenu:" "${S}"/opt/google/desktop/bin/pre_uninstall.sh
}

src_install() {
        mv -f * ${D}/
}

pkg_postinst() {
        /opt/google/desktop/bin/post_install.sh -G /opt/google/desktop

        if [ ! -e /var/cache/google/desktop/id ] ; then
            LD_LIBRARY_PATH=/opt/google/desktop/lib /opt/google/desktop/bin/gdl_stats install &
        else
            LD_LIBRARY_PATH=/opt/google/desktop/lib /opt/google/desktop/bin/gdl_stats update &
            killall -USR2 gdl_box 2> /dev/null || :
        fi
}

pkg_prerm() {
        # Call pre_uninstall.sh only when uninstall
        killall gdl_service 2> /dev/null || :
        killall gdl_box 2> /dev/null || :
        /opt/google/desktop/bin/pre_uninstall.sh -G /opt/google/desktop
}

pkg_postrm() {
        # Delete repositories for all users when uninstall.
        if [ -e /var/cache/google/desktop ]; then
            for i in /var/cache/google/desktop/*; do
                # don't remove machine id file.
                if [ -d "$i" ]; then
                    rm -rf "$i"
                fi
            done
        fi
        for dir in /home/* /root; do
            if [ -d "$dir" -a -d "$dir/.google/desktop" ]; then
                rm -fr "$dir/.google/desktop"
            fi
        done
}
